@layout("/common/_curd/_container.html"){

<script type="text/javascript">
    var ctx = "${basePath}";
    var grid_selector = "#grid-table";
    var pager_selector = "#grid-pager";

    $(function () {
        initGrid();
//        initMenuBtn("btns", "${code}");
    });

    function initGrid() {
        var grid_url = ctx + "/${code}/list";
        var _colnames = ["",
            "入库时间",
            "查询时间",
            "出库时间",
            "库存流水号",
            "商品代码",
            "商品名称",
            "摘要",
            "订单号",
            "入库数量",
            "入库单价",
            "入库金额",
            "出库数量",
            "出库单价",
            "出库金额",
            "剩余库存",
            "剩余价值",
            "剩余单价",
            "供应商",
            "经办人"
        ];
        var _colmodel = [{name: "id", index: "id", hidden: true, width: 100},
            {
                name: "in_time", index: "in_time", width: 100, formatter: function (value, rows, index) {
                if (value == null || value == "null" || value == "") {
                    var v = index.out_time;
                    if (v == null || v == "null" || v == "") {
                        return "没有选择时间";
                    } else {
                        return v.substring(0, 10)
                    }

                } else {
                    return value.substring(0, 10);
                }

            }
            },
            {name: "query_time", index: "query_time", hidden: true, width: 100},
            {name: "out_time", index: "out_time", hidden: true, width: 100},
            {name: "bianhao", index: "bianhao", width: 100},
            {name: "g_bianhao", index: "g_bianhao", width: 100},
            {name: "g_name", index: "g_name", width: 100},
            {name: "company", index: "company", width: 100},
            {name: "order_id", index: "order_id", hidden: true, width: 100},
            {
                name: "in_num", index: "in_num", width: 100, formatter: function (value, rows, index) {
                if (value == null || value == "") {
                    return "";
                } else {
                    return value;
                }
            }
            },
            {
                name: "g_price", index: "g_price", width: 100, formatter: function (value, rows, index) {
                var innum = index.in_num;
                if (innum == null || innum == "") {
                    return "";
                } else {
                    return value;
                }

            }
            },
            {
                name: "in_totle", index: "in_totle", width: 100, formatter: function (value, rows, index) {
                var innum = index.in_num;
                if (innum == null || innum == "") {
                    return "";
                } else {
                    var price = index.g_price;
                    return price * innum;
                }

            }
            },
            {
                name: "out_num", index: "out_num", width: 100, formatter: function (value, rows, index) {
                if (value == null || value == "") {
                    return "";
                } else {
                    return value;
                }
            }
            },
            {
                name: "final_price", index: "final_price", width: 100, formatter: function (value, rows, index) {
                var outnum = index.out_num;
                if (outnum == null || outnum == "") {
                    return "";
                } else {
                    if (value == null || value == "") {
                        return 0;
                    } else {
                        return value;
                    }
                }

            }
            },
            {
                name: "totle_price", index: "totle_price", width: 100, formatter: function (value, rows, index) {
                var outnum = index.out_num;
                if (outnum == null || outnum == "") {
                    return "";
                } else {
                    var price = index.final_price;
                    return price * outnum;
                }
            }
            },
            {
                name: "kucun_now", index: "kucun_now", width: 100, formatter: function (value, rows, index) {
                var outnum = value;
                if (outnum == null || outnum == "") {
                    return "0";
                } else {
                    return value;
                }
            }
            },
            {
                name: "price_now", index: "price_now", width: 100, formatter: function (value, rows, index) {

                if (value == null || value == "") {
                    return "0";
                } else {
                    return value;
                }
            }
            },
            {name: "final_price", index: "final_price", width: 100},
            {name: "sname", index: "sname", hidden: true, width: 100},
            {name: "uname", index: "uname", hidden: true, width: 100}
//						{name:"g_id", index:"g_id", width:100},
//						{name:"g_price", index:"g_price", width:100},
//						{name:"totle_price", index:"totle_price", width:100},
        ];

        jQuery(grid_selector).jqGrid({
            url: grid_url,
            shrinkToFit: true,
            colNames: _colnames,
            colModel: _colmodel,
            jsonReader: {id: "id"},
            pager: pager_selector,
//                footerrow:true,
                postData: {sort: "id", order: "asc"}
//        ,gridComplete:function(){
//            var sumValue = $(this).getCol('price_now', false, 'sum');
//            $(this).footerData('set', {kucun_now:"总计",price_now:sumValue},false);
//        }
        });
    }
</script>

<!-- 配置 grid -->
<div class="row">
    <div class="col-xs-12 tb-grid">

        <div class="col-xs-8 input-group">

            <!-- 简单查询第一组 -->
            <div class="input-group-btn">
                <button data-toggle="dropdown" class="btn btn-sx btn-white dropdown-toggle" aria-expanded="false">
                    <span id="searchthis1">起始时间</span>
                </button>
                <ul class="dropdown-menu">
                    <li>
                        <a href="#" onclick="changethis('query_time_dategt','起始时间','laydate',1)">
                            起始时间
                        </a>
                    </li>
                </ul>
            </div>
            <div ><input type="text" id="apply_date1" class="form-control" style="margin-left:-3px;"></div>
            <span class="input-group-btn"></span>

            <!-- 简单查询第2组 -->
            <div class="input-group-btn">
                <button data-toggle="dropdown" class="btn btn-sx btn-white dropdown-toggle" aria-expanded="false">
                    <span id="searchthis2">结束时间</span>
                </button>
                <ul class="dropdown-menu">
                    <li>
                        <a href="#" >
                            结束时间
                        </a>
                    </li>
                </ul>
            </div>
            <div ><input type="text" id="apply_date2" class="form-control" style="margin-left:-3px;"></div>
            <span class="input-group-btn"></span>
            <!-- 简单查询第3组 -->
            <div class="input-group-btn">
                <button data-toggle="dropdown" class="btn btn-sx btn-white dropdown-toggle" aria-expanded="false">
                    <span id="searchthis3">商品名</span>
                </button>
            </div>
            <div id="divinput1"><input type="text" id="gname" class="form-control" style="margin-left:-3px;"></div>
            <input type="hidden" id="hides1" value="query_time_dategt">
            <span class="input-group-btn"></span>
            <!-- 简单查询按钮 -->
            <div class="input-group-btn">
                <button class="btn btn-sx btn-white" onclick="gotoSearch()">查询</button>
            </div>
        </div>


        <!-- 按钮 -->
        <div class="welljq well-sm" id="btns">
            <button class="btn btn-xs btn-white" onclick="_add()">&nbsp;
                <li class="fa fa-floppy-o bigger-120"></li>
                &nbsp;新增出入库&nbsp;</button>
            &nbsp;
            <!--<button class="btn btn-xs btn-white " id="snStore_edit">&nbsp;-->
                <!--<li class="fa fa-pencil  bigger-120"></li>-->
                <!--&nbsp;分公司领用情况&nbsp;</button>-->
            <!--&nbsp;-->
            <!--<button class="btn btn-xs btn-white " id="snStore_view">&nbsp;-->
                <!--<li class="fa fa-eye bigger-120"></li>-->
                <!--&nbsp;查看&nbsp;</button>-->
            <!--&nbsp;-->
            <!--<button class="btn btn-xs btn-white " id="snStore_remove">&nbsp;-->
                <!--<li class="fa fa-times  bigger-120"></li>-->
                <!--&nbsp;删除&nbsp;</button>-->
            &nbsp;</div>
        <!-- grid -->
        <table id="grid-table"></table>
        <!-- 分页-->
        <div id="grid-pager"></div>
    </div>
</div>
<script>
    gotoSearch = function(){

        $jqGrid.jqGrid("setGridParam", { postData: { sort : "id",
                start:$("#apply_date1").val(),
                over:$("#apply_date2").val(),
                gname:$("#gname").val(),
                order : "desc" }, page: 1 }).trigger("reloadGrid");

    }
    _add = function () {
        console.log(122)

        var index = layer.open({
            type: 2,
            title:'新增',
            area: ['100%', '100%'],
            maxmin:true,
            shadeClose: true, //点击遮罩关闭
            content:  '/snStore/add',
            end:function () {
                console.log(123)
                $jqGrid.jqGrid("setGridParam", { postData: { sort : "id",order : "asc" }, page: 1 }).trigger("reloadGrid");
            }
        });

        this.layerIndex = index;
    }
</script>
<script src="/static/blade/js/laydate/laydate.js"></script>
<script>
    $(function () {
            laydate.render({
                elem: '#apply_date1'
            });
        laydate.render({
            elem: '#apply_date2'
        });
    })


</script>
<!-- 引入所需的js -->
@include("/common/_listscript.html"){}

@}	